/// MIXINS

@mixin viewport-small {
  @media (width < 600px) {
    @content;
  }
}

@mixin viewport-medium {
  @media (width >= 600px) {
    @content;
  }
}

@mixin viewport-large {
  @media (width >= 950px) {
    @content;
  }
}

:root {
  /* z-index enum */
  --z-index-popup: 2;

  /* various dimensions */
  --dialog-logo-padding: calc(var(--dialog-padding) * 0.66);
  --dialog-padding: 20px;
  --logo-size: 64px;
  --popup-top: 82px; // TODO: ugly that this is hardcoded
  --toolbar-height: 50px;

  /* colors related to torrent status */
  --black: #000;
  --blue-100: #51b3f7;
  --blue-200: #357aaa;
  --blue-300: #2c7fea;
  --blue-400: #1847d4;
  --dark-mode-black: #121212;
  --dark-mode-white: #c9d1d9;
  --default-accent-color-dark: #0c2d6b;
  --default-border-dark: #575757;
  --default-border-light: #aeaeae;
  --default-tinted: rgba(128, 128, 144, 0.125);
  --green-100: #26aa55;
  --green-300: #7cef99;
  --green-400: #67c87f;
  --green-500: #34dc70;
  --grey: rgba(128, 128, 130, 0.66);
  --grey-200: #e1e4e8;
  --grey-40: #666;
  --grey-500: #828282;
  --grey-900: #191919;
  --nice-grey: #f8f8f8;
  --red-500: #d73a49;
  --white: #fff;
  --yellow-300: #ffea7f;

  /* ICONS -- see assets/img/README.md for sources and license details */
  /* Are you a designer? New icon PRs welcomed! */
  --image-alt-speed-disabled: url('../img/modern-tortoise.png');
  --image-alt-speed-enabled: url('../img/modern-tortoise-blue.png');
  --image-baseline: url('../img/horizontal-rule.svg');
  --image-chevron-dn: url('../img/chevron-down.svg');
  --image-chevron-up: url('../img/chevron-up.svg');
  --image-lock-fill: url('../img/lock-fill.svg');
  --image-magnet: url('../img/magnet.svg');

  --app-image-url: url('../img/box.svg');
  --audio-image-url: url('../img/music.svg');
  --folder-image-url: url('../img/folder.svg');
  --font-image-url: url('../img/type.svg');
  --image-image-url: url('../img/image.svg');
  --package-image-url: url('../img/package.svg');
  --text-image-url: url('../img/file-text.svg');
  --video-image-url: url('../img/film.svg');

  --progress: 100%;

  --color-bg-even: var(--default-tinted);
  --color-bg-tabs: var(--default-tinted);
  --color-fg-error: var(--red-500);
  --color-fg-port-closed: var(--red-500);
  --color-fg-port-open: var(--green-100);
  --color-progressbar-background-2: var(--green-400);
  --color-progressbar-leech: var(--blue-200);
  --color-progressbar-magnet: var(--yellow-300);
  --color-progressbar-paused: var(--grey-200);
  --color-progressbar-queued: var(--blue-400);
  --color-progressbar-verify: var(--yellow-300);
  --color-toolbar-background: var(--default-tinted);

  color-scheme: light dark;

  @media (prefers-color-scheme: dark) {
    --color-bg-hover: var(--grey-40);
    --color-bg-odd: var(--black);
    --color-bg-popup: var(--black);
    --color-bg-primary: var(--black);
    --color-bg-selected: var(--default-accent-color-dark);
    --color-bg-warn: #cf6679;
    --color-border-default: var(--default-border-dark);
    --color-border-stark: var(--dark-mode-white);
    --color-border-starkest: var(--grey-500);
    --color-fg-disabled: var(--grey);
    --color-fg-on-popup: var(--nice-grey);
    --color-fg-primary: var(--dark-mode-white);
    --color-fg-secondary: var(--nice-grey);
    --color-fg-selected: var(--dark-mode-white);
    --color-fg-tertiary: var(--grey-500);
    --color-fg-warn: var(--dark-mode-black);
    --color-progressbar-fg-1: #edefff;
    --color-progressbar-fg-2: #edefff;
    --color-progressbar-fg-3: #edefff;
    --color-progressbar-paused: var(--grey-500);
    --color-progressbar-seed-1: var(--green-100);
    --color-progressbar-seed-2: var(--green-400);
    --color-progressbar-seed-paused: var(--grey-500);
    --progress-bar-shadow-1: 1px 1px #000;
    --progress-bar-shadow-2: 1px 1px #000;
    --progress-bar-shadow-3: 1px 1px #000;

    .contrast-more {
      --color-bg-even: var(--black);
      --color-bg-hover: var(--grey-40);
      --color-bg-selected: var(--blue-300);
      --color-bg-tabs: var(--black);
      --color-bg-warn: #cf6679;
      --color-border-default: var(--white);
      --color-border-stark: var(--white);
      --color-border-starkest: var(--white);
      --color-fg-disabled: var(--white);
      --color-fg-error: var(--red-500);
      --color-fg-on-popup: var(--white);
      --color-fg-port-closed: var(--red-500);
      --color-fg-port-open: var(--green-100);
      --color-fg-primary: var(--white);
      --color-fg-secondary: var(--white);
      --color-fg-selected: var(--white);
      --color-fg-tabs: var(--white);
      --color-fg-tertiary: var(--white);
      --color-fg-warn: var(--black);
      --color-progressbar-fg-1: #fff;
      --color-progressbar-fg-2: #fff;
      --color-progressbar-fg-3: #000;
      --color-progressbar-background-2: var(--white);
      --color-progressbar-magnet: var(--yellow-300);
      --color-progressbar-paused: var(--grey-500);
      --color-progressbar-queued: var(--blue-400);
      --color-progressbar-seed-1: var(--black);
      --color-progressbar-seed-2: var(--white);
      --color-progressbar-seed-paused: var(--grey-500);
      --color-progressbar-verify: var(--yellow-300);
      --color-toolbar-background: var(--black);
      --progress-bar-shadow-3: 0;
    }
  }
  @media (prefers-color-scheme: light) {
    --color-bg-hover: var(--nice-grey);
    --color-bg-odd: var(--white);
    --color-bg-popup: var(--white);
    --color-bg-primary: var(--white);
    --color-bg-selected: var(--blue-300);
    --color-bg-warn: #e4606d5b;
    --color-border-default: var(--default-border-light);
    --color-border-stark: var(--grey-500);
    --color-border-starkest: #d0d7de;
    --color-dialog-border: var(--nice-grey);
    --color-fg-disabled: var(--grey);
    --color-fg-error: var(--red-500);
    --color-fg-on-popup: var(--grey-900);
    --color-fg-port-closed: var(--red-500);
    --color-fg-port-open: var(--green-400);
    --color-fg-primary: #404040;
    --color-fg-secondary: var(--grey-500);
    --color-fg-selected: var(--nice-grey);
    --color-fg-tertiary: var(--grey-500);
    --color-fg-warn: #cf212e;
    --color-progressbar-fg-1: #303030;
    --color-progressbar-fg-2: #edefff;
    --color-progressbar-fg-3: #edefff;
    --color-progressbar-leech: var(--blue-100);
    --color-progressbar-magnet: var(--yellow-300);
    --color-progressbar-paused: var(--grey-200);
    --color-progressbar-queued: var(--blue-400);
    --color-progressbar-seed-1: var(--green-500);
    --color-progressbar-seed-2: var(--green-300);
    --color-progressbar-seed-paused: var(--grey-200);
    --color-progressbar-verify: var(--yellow-300);
    --progress-bar-shadow-1: 0;
    --progress-bar-shadow-2: 1px 1px #000;
    --progress-bar-shadow-3: 1px 1px #000;

    .contrast-more {
      --color-bg-even: var(--white);
      --color-bg-hover: var(--grey-40);
      --color-bg-selected: var(--blue-300);
      --color-bg-tabs: var(--white);
      --color-bg-warn: #cf6679;
      --color-border-default: var(--black);
      --color-border-stark: var(--black);
      --color-border-starkest: var(--black);
      --color-fg-disabled: var(--black);
      --color-fg-error: var(--red-500);
      --color-fg-on-popup: var(--black);
      --color-fg-port-closed: var(--red-500);
      --color-fg-port-open: var(--green-400);
      --color-fg-primary: var(--black);
      --color-fg-secondary: var(--black);
      --color-fg-selected: var(--white);
      --color-fg-tabs: var(--black);
      --color-fg-tertiary: var(--black);
      --color-fg-warn: var(--white);
      --color-progressbar-background-2: var(--white);
      --color-progressbar-fg-1: #fff;
      --color-progressbar-fg-2: #fff;
      --color-progressbar-fg-3: #000;
      --color-progressbar-leech: var(--blue-200);
      --color-progressbar-magnet: var(--yellow-300);
      --color-progressbar-paused: var(--grey-500);
      --color-progressbar-queued: var(--blue-400);
      --color-progressbar-seed-1: var(--black);
      --color-progressbar-seed-2: var(--white);
      --color-progressbar-seed-paused: var(--grey-500);
      --color-progressbar-verify: var(--yellow-300);
      --color-toolbar-background: var(--white);
      --progress-bar-shadow-1: 1px 1px #000;
      --progress-bar-shadow-3: 0;
    }
  }
}

/* If browser can support using 'system color' keywords (i.e. way to inherit browser colors), use these variables instead */
@supports (background-color: Canvas) {
  :root {
    .contrast-less {
      --color-bg-odd: Canvas;
      --color-bg-primary: Canvas;
      --color-bg-popup: Canvas;
    }
  }
}

html,
body {
  background-color: var(--color-bg-primary);
  color: var(--color-fg-primary);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica,
    Arial, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol';
  height: 100%;
  margin: 0;
}

img {
  border: 0;
}

a {
  color: var(--color-fg-primary);
  outline: 0;
  text-decoration: underline;
}

.hidden {
  display: none;
}

#mainwin {
  display: flex;
  flex-direction: column;
  height: 100%;
  position: relative;

  > * {
    margin: 0;
    padding: 0;
  }

  .flexible-space {
    margin-right: auto;
  }
}

#mainwin-workarea {
  display: flex;
  flex: 1;
  flex-direction: row;
  overflow: auto;
}

.popup,
.tabs-container {
  box-shadow:
    0 3px 6px -4px rgba(0, 0, 0, 0.12),
    0 6px 16px rgba(0, 0, 0, 0.08),
    0 9px 28px 8px rgba(0, 0, 0, 0.06);
  position: absolute;
}

/// TOOLBAR

#mainwin-toolbar {
  align-items: center;
  background: var(--color-toolbar-background);
  border-bottom: 1px solid var(--color-border-default);
  display: flex;
  flex-direction: row;
  height: var(--toolbar-height);
  margin: 0;
  width: 100%;

  button {
    background-color: transparent;
    background-position: center;
    background-repeat: no-repeat;
    border: 0;
    border-radius: 5px;
    cursor: pointer;
    height: var(--toolbar-height);
    margin-right: 6px;
    user-select: none;
    -webkit-user-select: none;
    width: var(--toolbar-height);

    svg {
      stroke: var(--color-fg-primary);

      g path {
        fill: var(--color-fg-primary);
      }
    }

    &:disabled {
      cursor: default;

      svg {
        stroke: var(--color-fg-disabled);

        g path {
          fill: var(--color-fg-disabled);
        }
      }
    }
  }

  > .toolbar-separator {
    border-left: 1px solid var(--color-border-default);
    height: 25px;
    margin: 0 6px 0 0;
  }

  :nth-last-child(2) {
    border: 0;
    flex-grow: 1;
  }
}

.toolbar-icon {
  stroke: var(--color-fg-primary);
}

#toolbar-overflow {
  margin-right: 4px;

  svg {
    fill: var(--color-fg-primary);
    height: 36px;
    width: 36px;
  }

  &.alt-speed-enabled {
    background-image: var(--image-alt-speed-enabled);
    background-position: bottom left;
    background-size: 20px;
  }
}

/// FILTERBAR

#mainwin-statusbar {
  white-space: nowrap;
  align-items: center;
  background: var(--color-toolbar-background);
  border-bottom: 1px solid var(--color-border-default);
  display: flex;
  flex-direction: row;
  height: 30px;
  padding-left: 5px;

  @include viewport-small {
    :not(select):not(input):not(option):not(.flexible-space) {
      display: none;
    }
  }

  #torrent-search {
    width: 100%;
    max-width: 160px;
  }

  select {
    width: 70px;
  }

  > * {
    margin-right: 5px;
  }

  .speed-container {
    display: inherit;
    align-items: inherit;
    flex-direction: inherit;

    + .speed-container {
      min-width: 100px;
    }
  }

  #speed-up-icon,
  #speed-dn-icon {
    fill: var(--color-fg-primary);

    svg {
      width: 20px;
    }
  }

  #speed-dn-label,
  #speed-up-label {
    text-align: right;
  }
}

/// TORRENT CONTAINER

#torrent-container {
  flex-grow: 1;
  left: 0;
  margin: 0;
  overflow: auto;
  padding: 0;
  right: 0;
}

#torrent-list {
  cursor: pointer;
  list-style-type: none;
  margin: 0;
  padding: 0;
  text-align: left;
  width: 100%;
  user-select: none;
  -webkit-user-select: none;

  .torrent {
    align-items: center;
    border-bottom: 1px solid var(--color-border-default);
    display: grid;

    &:nth-child(even) {
      background-color: var(--color-bg-even);
    }

    &:nth-child(odd) {
      background-color: var(--color-bg-odd);
    }

    .icon {
      // color the background svg fill
      background-color: var(--color-fg-primary);
      background-position:
        center,
        top left;
      -webkit-mask-image: var(--mime-icon-url);
      -webkit-mask-repeat: no-repeat;
      mask-image: var(--mime-icon-url);
      mask-repeat: no-repeat;

      &[data-icon-multifile='true'] {
        -webkit-mask-image: var(--mime-icon-url), var(--folder-image-url);
        -webkit-mask-position:
          top left,
          bottom right;
        -webkit-mask-repeat: no-repeat, no-repeat;
        -webkit-mask-size: 16px, 16px;
        mask-image: var(--mime-icon-url), var(--folder-image-url);
        mask-position:
          top left,
          bottom right;
        mask-repeat: no-repeat, no-repeat;
        mask-size: 16px, 16px;
      }

      &[data-icon-mime-type='audio'] {
        --mime-icon-url: var(--audio-image-url);
      }

      &[data-icon-mime-type='application'] {
        --mime-icon-url: var(--app-image-url);
      }

      &[data-icon-mime-type='font'] {
        --mime-icon-url: var(--font-image-url);
      }

      &[data-icon-mime-type='image'] {
        --mime-icon-url: var(--image-image-url);
      }

      &[data-icon-mime-type='model'] {
        --mime-icon-url: var(--package-image-url);
      }

      &[data-icon-mime-type='text'] {
        --mime-icon-url: var(--text-image-url);
      }

      &[data-icon-mime-type='video'] {
        --mime-icon-url: var(--video-image-url);
      }
    }

    .torrent-name {
      font-weight: bold;
      grid-area: name;
      margin-bottom: 2px;
      margin-top: 2px;
      overflow: hidden;
      text-overflow: ellipsis;
      white-space: nowrap;

      &.compact {
        font-size: 1em;
        font-weight: normal;
      }
    }

    .torrent-labels {
      font-size: small;
      font-weight: normal;
      grid-area: labels;
      margin-bottom: 2px;
      margin-top: 2px;
      overflow: hidden;
      text-overflow: ellipsis;
      white-space: nowrap;
      padding: 1px 0;

      &.compact {
        flex: 1;
        font-size: small;
      }
    }

    .torrent-label {
      padding: 0 8px;
      margin: 0 2px;
      border-radius: 1em;
      border: 1px solid var(--color-border-default);
    }

    .torrent-peer-details {
      grid-area: peers;
    }

    .torrent-progress-bar {
      grid-area: progressbar;
    }

    .torrent-progress-details {
      grid-area: progress-text;
    }

    .torrent-peer-details,
    .torrent-progress-details {
      font-size: small;

      &.error {
        color: var(--color-fg-error);
      }
    }

    &.compact {
      --icon-size: 16px;

      grid-template-areas: 'icon name labels peers progressbar';
      grid-template-columns: calc(var(--icon-size) + 10px) auto 1fr auto auto;

      .icon {
        -webkit-mask-size: var(--icon-size), calc(var(--icon-size) / 2);
        height: var(--icon-size);
        mask-size: var(--icon-size), calc(var(--icon-size) / 2);
        width: var(--icon-size);

        &[data-icon-multifile='true'] {
          --mime-icon-url: var(--folder-image-url);
        }
      }

      .torrent-peer-details {
        white-space: nowrap;
      }

      > * {
        margin: 5px;
      }
    }

    &:not(.compact) {
      --icon-size: 32px;

      grid-column-gap: 12px;
      grid-template-areas:
        'icon name labels'
        'icon progress-text progress-text'
        'icon progressbar progressbar'
        'icon peers peers';
      grid-template-columns: var(--icon-size) auto 1fr;
      padding: 6px 12px;

      .icon {
        background-size: var(--icon-size), calc(var(--icon-size) / 2);
        grid-area: icon;
        height: var(--icon-size);
        width: var(--icon-size);
      }

      .torrent-progress-bar {
        display: flex;
        flex-direction: row;
      }

      > * {
        margin: 1px 0;
      }
    }

    &.paused {
      color: var(--color-fg-disabled);

      &:not(.selected) .torrent-progress-bar {
        color: var(--color-fg-primary);
      }

      .icon {
        background-color: var(--color-fg-disabled);
      }
    }

    &.selected {
      background-color: var(--color-bg-selected);
      color: var(--color-fg-selected);

      .icon {
        background-color: var(--color-fg-selected);
      }
    }
  }

  .icon {
    background-position: center;
    background-repeat: no-repeat;
  }

  .torrent-progress-bar {
    font-size: 14px;
    position: relative;
    border: 1px solid var(--color-border-starkest);
    border-radius: 3px;
    height: 18px;

    &:not(.compact) {
      flex-grow: 1;
      margin: 2px 0;
    }

    &.compact {
      min-width: 100px;
    }

    &.leech {
      &.queued::before {
        background: var(--color-progressbar-queued);
      }

      &::before {
        background: var(--color-progressbar-leech);
        color: var(--color-progressbar-fg-2);
        text-shadow: var(--progress-bar-shadow-2);
      }
    }

    &.magnet::before {
      background: var(--color-progressbar-magnet);
      color: #000;
    }

    &.seed {
      &.paused::before {
        background: var(--color-progressbar-seed-paused);
        color: var(--color-progressbar-fg-1);
        text-shadow: var(--progress-bar-shadow-1);
      }

      &:not(.paused) {
        &::before {
          background: var(--color-progressbar-seed-1);
          color: var(--color-progressbar-fg-2);
          text-shadow: var(--progress-bar-shadow-2);
        }

        &::after {
          background: var(--color-progressbar-seed-2);
          color: var(--color-progressbar-fg-3);
          text-shadow: var(--progress-bar-shadow-3);
        }
      }

      &.queued::before {
        background-color: var(--color-progressbar-seed-1);
      }

      &::before {
        background-color: var(--color-progressbar-seed-1);
        color: var(--color-progressbar-fg-2);
        text-shadow: var(--progress-bar-shadow-2);
      }
    }

    &.verify::before {
      background: var(--color-progressbar-verify);
      color: #000;
    }

    &.paused::before {
      background: var(--color-progressbar-paused);
      color: var(--color-progressbar-fg-1);
      text-shadow: var(--progress-bar-shadow-1);
    }

    &::before,
    &::after {
      content: attr(data-progress);
      height: 100%;
      width: 100%;
      position: absolute;
      border-radius: 2px;
      text-align: center;
    }

    &::before {
      clip-path: polygon(
        0 0,
        var(--progress, 30%) 0,
        var(--progress, 30%) 100%,
        0 100%
      );
    }

    &::after {
      clip-path: polygon(
        var(--progress, 30%) 0,
        100% 0,
        100% 100%,
        var(--progress, 30%) 100%
      );
    }
  }
}

/// PREFERENCES DIALOG

@include viewport-small {
  input[type='checkbox'] {
    height: 20px;
    width: 20px;
  }
}

#inspector {
  @include viewport-large {
    box-shadow: initial;
    position: initial;
  }
}

#prefs-dialog {
  $background-color: var(--color-bg-primary);
  background: $background-color;
  bottom: 0;
  right: 0;
  z-index: var(--z-index-popup);

  .tabs-page {
    grid-column-gap: 8px;
    grid-row-gap: 5px;
    grid-template-columns: 1fr 1fr;
    margin: 20px;

    &:not(.hidden) {
      display: grid;
    }

    .section-label {
      font-weight: bold;
      grid-column: span 2;
      // margin-left: -20px;
      padding-bottom: 5px;

      &:not(:first-of-type) {
        margin-top: 20px;
      }
    }
  }

  .alt-speed-section-label {
    background: transparent var(--image-alt-speed-enabled) no-repeat;
    background-position: left;
    background-position-y: 4px;
    background-size: 20px;
    padding-left: 22px;
  }

  :disabled,
  .disabled {
    color: var(--color-fg-disabled);
  }

  #alt-times-div,
  #autostart-div,
  #port-forwarding,
  #randomize-port,
  #suffix-div,
  #use-dht-div,
  #use-lpd-div,
  #use-pex-div,
  #utp-enabled,
  .alt-speed-label {
    grid-column: span 2;
  }

  #default-trackers {
    height: 300px;
  }

  .blocklist-size-label,
  .blocklist-update-button,
  .register-handler-button,
  .port-status {
    grid-column: 2 / 3;
  }

  .blocklist-size-label {
    font-size: smaller;
  }

  .blocklist-size-number {
    font-weight: bolder;
  }

  .port-status-label {
    display: inline-block;
    font-weight: bold;
    margin-left: 5px;

    &[data-open='true'] {
      color: var(--color-fg-port-open);
    }

    &[data-open='false'] {
      color: var(--color-fg-port-closed);
    }
  }

  #default-trackers,
  .default-trackers-label {
    grid-column: 1 / 3;
  }

  .alt-speed-label {
    font-size: smaller;
    // nudge it up next to the section label
    margin: -10px 0 10px;
  }
}

#prefs-dialog.ui-tabs .ui-tabs-panel {
  padding: 0;
  user-select: none;
  -webkit-user-select: none;
}

/// TABS

.tabs-container {
  align-items: stretch;
  background: var(--color-bg-primary);
  bottom: 0;
  display: flex;
  flex-direction: column;
  position: absolute;
  right: 0;
  top: var(--popup-top);
  z-index: var(--z-index-popup);

  @include viewport-small {
    top: 0;
    left: 0;
  }
  @include viewport-medium {
    border-left: 1px solid var(--color-border-default);
    min-width: 570px;
    width: 570px;
  }
}

.tabs-container-close {
  font-size: 150%;
  cursor: pointer;
  background: var(--color-bg-primary);
  border: 0;
  color: var(--color-fg-primary);
  position: absolute;
  padding: 10px 16px;
}

.tabs-buttons {
  align-self: center;
  background-color: var(--color-bg-tabs);
  border: 1px solid var(--color-border-starkest);
  border-radius: 6px;
  display: flex;
  margin: 10px 0;

  button {
    appearance: none;
    border: 1px solid transparent;
    border-radius: 6px;
    color: var(--color-fg-primary);
    font-weight: 400;
  }
}

.tabs-pages {
  box-sizing: border-box;
  flex: 1;
  overflow-x: hidden;
  overflow-y: auto;

  @include viewport-small {
    padding: 0 8px 20px;
  }
  @include viewport-medium {
    padding: 0 20px 20px;
  }
}

.tabs-button {
  background: none;
  border: 1px solid transparent;
  font-size: 14px;
  padding: 3px 8px;

  &:active,
  &:checked,
  &.selected {
    background-color: var(--color-bg-odd);
    border: 1px solid var(--color-fg-primary);
    border-radius: 5px;
  }
}

/// INSPECTOR

.inspector-info-page {
  font-size: 14px;
  // TODO: this is (mostly) copied from prefs-dialog.
  // can it be folded into a single set of rules?

  grid-column-gap: 8px;
  grid-row-gap: 8px;
  grid-template-columns: auto 1fr;
  margin: 20px;
  padding: 12px;

  &:not(.hidden) {
    display: grid;
  }

  .section-label {
    font-size: 16px;
    font-weight: bold;
    grid-column: span 2;
    padding-bottom: 5px;

    &:not(:first-of-type) {
      margin-top: 20px;
    }
  }

  label {
    font-weight: 500;
  }

  :not(.section-label) {
    // this section is not copied
    overflow-x: hidden;
    text-overflow: ellipsis;
  }
}

.inspector-info-magnet button {
  background-color: var(--color-fg-primary);

  background-position: top;
  background-repeat: no-repeat;
  border: 0;
  cursor: pointer;
  height: 1rem;
  -webkit-mask: var(--image-magnet) no-repeat center / 14px;
  mask: var(--image-magnet) no-repeat center / 14px;
  vertical-align: middle;
  width: 1rem;
}

#inspector,
#prefs-dialog {
  .tabs-button {
    height: 30px;
    margin: 0;
    min-width: 40px;
  }
}

#inspector-file-list {
  margin: 0;
  padding: 0;

  .inspector-torrent-file-list-entry {
    display: grid;
    grid-column-gap: 5px;
    grid-template-areas:
      'check   name  priority'
      'blank1  info  blank2';
    grid-template-columns: 20px 1fr 65px;
    margin-bottom: 4px;
    padding: 5px;

    &:nth-child(even) {
      background-color: var(--color-bg-even);
    }

    &:nth-child(odd) {
      background-color: var(--color-bg-odd);
    }

    &.skip {
      opacity: 0.5;
    }
  }

  .file-wanted-control {
    grid-area: check;
  }

  .inspector-torrent-file-list-entry-name {
    color: var(--color-fg-primary);
    cursor: pointer;
    font-size: 14px;
    grid-area: name;
    overflow-wrap: anywhere;
  }

  .inspector-torrent-file-list-entry.skip
    > .inspector-torrent-file-list-entry-name {
    color: var(--color-fg-disabled);
  }

  .inspector-torrent-file-list-entry-progress {
    color: var(--color-fg-secondary);
    font-size: 12px;
    grid-area: info;
  }

  .single-file .inspector-torrent-file-list-entry,
  .inspector-torrent-file-list-entry.complete {
    > .file-wanted-control {
      cursor: default;
    }
  }
}

#inspector-header {
  margin: 8px 0;
}

#torrent-inspector-name {
  font-size: large;
  font-weight: bold;
}

#inspector-tiers-list {
  color: var(--color-fg-primary);
  margin: 0 10px;
  padding: 0;

  .tier-list-row {
    display: grid;
    font-size: 12px;
    grid-column-gap: 8px;
    grid-row-gap: 4px;
    padding: 8px 12px;

    &:nth-child(even of .tier-list-row) {
      background-color: var(--color-bg-even);
    }

    &:nth-child(odd of .tier-list-row) {
      background-color: var(--color-bg-odd);
    }
  }

  .tier-list-torrent {
    color: var(--color-fg-primary);
    font-weight: bolder;
    overflow-x: hidden;
    padding-top: 12px;
    padding-bottom: 8px;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .tier-list-tracker {
    font-size: 14px;
    font-weight: bolder;
    grid-column: span 2;
    padding-bottom: 4px;
  }

  .tier-announce,
  .tier-scrape,
  .tier-state {
    text-align: left;
  }

  .tier-downloads,
  .tier-leechers,
  .tier-seeders {
    text-align: right;
  }
}

// Peers Tab

.peer-list {
  --table-border: 1px solid var(--color-border-default);

  border: var(--table-border);
  border-collapse: collapse;
  cursor: default;
  table-layout: fixed;
  text-align: left;
  width: 100%;

  td,
  th {
    font-size: smaller;
    padding: 5px;
  }

  td {
    border: var(--table-border);
    color: var(--color-fg-secondary);
    // padding: 5px 10px;
  }

  .torrent-row td {
    background: var(--color-bg-odd);
    color: var(--color-fg-primary);
    font-weight: bolder;
    overflow-x: hidden;
    padding: 10px;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .encryption[data-encrypted='true'] {
    background-color: var(--color-border-starkest);
    -webkit-mask: var(--image-lock-fill) no-repeat center / 14px;
    mask: var(--image-lock-fill) no-repeat center / 14px;
    width: 10px;
  }

  .peer-address,
  .percent-done,
  .speed-down,
  .speed-up {
    text-align: right;
  }

  .percent-done {
    width: 10%;

    @include viewport-small {
      width: 12%;
    }
  }

  .speed-down,
  .speed-up {
    width: 15%;
  }

  .peer-address {
    width: 25%;
    overflow-x: hidden;
    text-overflow: ellipsis;

    @include viewport-small {
      text-align: left;
      width: 20%;
    }
  }

  .peer-app-name {
    overflow-x: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    @include viewport-medium {
      width: 20%;
    }
  }

  .status {
    cursor: pointer;
    width: 10%;
  }
}

/// FILE PRIORITY BUTTONS

.file-priority-radiobox {
  grid-area: priority;

  > * {
    appearance: none;
    background-color: var(--color-border-starkest);
    background-position: center;
    background-repeat: no-repeat;
    background-size: 10px, 20px;
    border: 1px solid var(--color-border-stark);
    border-radius: 0;
    height: 20px;
    margin: 0;
    padding: 0;
    width: 20px;
  }

  > .low {
    background-image: var(--image-chevron-dn);
    border-right-width: 0;
  }

  > .normal {
    background-image: var(--image-baseline);
  }

  > .high {
    background-image: var(--image-chevron-up);
    border-left-width: 0;
  }

  //if input is checked then change the background color
  > .checked {
    background-color: var(--color-bg-hover);
  }
}

/// CONTEXT MENU

.context-menu {
  background-color: var(--color-bg-primary);
  border-radius: 5px;
  color: var(--color-fg-on-popup);
  padding: 10px 5px;
  z-index: 9999;
  user-select: none;
  -webkit-user-select: none;

  .context-menuitem {
    font-size: 13px;
    font-weight: 400;
    list-style: none;
    padding: 5px 15px;

    &:hover:not(:disabled),
    &:focus:not(:disabled) {
      background-color: var(--color-bg-hover);
      border-radius: 6px;
      cursor: pointer;
      font-weight: 500;
    }

    &:disabled {
      color: var(--color-fg-disabled);
      cursor: none;
    }

    &.warning:hover {
      background-color: var(--color-bg-warn);
      color: var(--color-fg-warn);
    }
  }
}

.context-menu-separator {
  border-bottom: 1px solid var(--color-fg-secondary);
  margin-bottom: 10px;
  padding-bottom: 10px;
}

/// OVERFLOW MENU

.overflow-menu {
  background: var(--color-bg-popup);
  border-radius: 5px;
  color: var(--color-fg-on-popup);
  overflow: auto;
  padding: 10px;

  right: 0;
  margin: 6px;
  top: 50px;
  z-index: var(--z-index-popup);

  @include viewport-small {
    height: 80vh;
  }

  fieldset {
    border: 0;
    display: block;
    margin: 8px 0;

    ul {
      margin: 0;
      padding-left: 0;

      li {
        list-style-type: none;
      }

      a {
        cursor: pointer;
      }
    }
  }

  .table-row {
    align-items: center;
    border-radius: 6px;
    display: flex;
    flex-direction: row;
    padding: 3px 0;
  }

  legend {
    color: var(--color-fg-primary);
    font-weight: bolder;
    margin: 12px 0 4px;
  }

  button,
  label {
    color: var(--color-fg-primary);
    display: inline-flex;
    font-size: 1em;
    width: 100%;
  }

  button {
    background: transparent;
    border: 0;
    cursor: pointer;
    display: block;
    padding: 4px 0;
    text-align: left;
    text-decoration: none;
    width: 150px;
  }

  .input-and-label {
    align-items: center;
    display: inline-flex;
    flex-direction: row;
  }

  #display-options {
    display: flex;
    flex-direction: column;
  }

  #speed-options {
    display: flex;
    flex-direction: column;

    > .speed-up,
    > .speed-down {
      align-items: center;
      display: flex;
      flex-direction: row;
      padding: 4px 0;

      > label {
        overflow: hidden;
        width: 80px;
      }
    }

    .alt-speed {
      display: grid;
      grid-column-gap: 5px;
      grid-row-gap: 5px;
      grid-template-areas:
        'check   lb'
        'turtle  values';
      grid-template-columns: 22px 1fr;
      margin-bottom: 4px;
    }

    #alt-speed-check {
      grid-area: check;

      &:checked ~ #alt-speed-image {
        background-image: var(--image-alt-speed-enabled);
        background-position: left;
        background-size: 22px;
      }

      &:not(:checked) ~ #alt-speed-image {
        background-image: var(--image-alt-speed-disabled);
        background-size: 22px;
      }
    }

    #alt-speed-image {
      background-position: center;
      background-repeat: no-repeat;
      grid-area: turtle;
    }

    #alt-speed-label {
      grid-area: lb;
    }

    #alt-speed-values-label {
      font-size: small;
      grid-area: values;
    }
  }
}

/// DIALOGS

@include viewport-small {
  .dialog-buttons {
    padding-top: var(--dialog-logo-padding);
  }

  .dialog-container {
    opacity: 96%;
    position: absolute;
    top: var(--popup-top);
    width: 100%;
  }

  .dialog-logo {
    padding-bottom: var(--dialog-logo-padding);
  }

  .dialog-window {
    align-items: center;
    display: flex;
    flex-direction: column;
  }
}

@include viewport-medium {
  .dialog-container {
    min-width: 500px;
    position: absolute;
    top: calc(var(--popup-top) * 2);
  }

  .dialog-heading {
    grid-area: heading;
  }

  .dialog-logo {
    grid-area: icon;
    padding-right: var(--dialog-logo-padding);
  }

  .dialog-window {
    background-color: var(--color-bg-popup);
    color: var(--color-fg-on-popup);
    display: grid;
    grid-column-gap: 12px;
    grid-template-areas:
      'icon heading'
      'icon message'
      'icon workarea'
      'icon buttons';
    grid-template-columns: var(--logo-size) 1fr;
    padding: 2px 12px;
  }
}

.dialog-buttons {
  display: flex;
  float: right;
  grid-area: buttons;
  margin: 10px 0 0;
  text-align: center;

  button {
    appearance: none;
    background: var(--color-bg-primary);
    border: 1px solid var(--color-border-default);
    border-radius: 5px;
    color: var(--color-fg-primary);
    margin-left: 8px;
    padding: 8px;
    text-decoration: none;
  }
}

.dialog-buttons-begin {
  flex-grow: 1;
}

.dialog-buttons-end {
  display: none;
}

dialog {
  border: 0;
}

.dialog-container {
  color: var(--color-fg-primary);
  display: block;
  padding: 0;
  z-index: var(--z-index-popup);

  @include viewport-medium {
    border: 0;
    border-radius: 8px;
    max-width: 50%;
  }
}

.dialog-heading {
  align-items: center;
  display: flex;
  font-size: 1.2em;
  font-weight: bold;
  overflow-wrap: anywhere;
}

.dialog-logo {
  background: transparent url('../img/logo.png') top left no-repeat;
  height: var(--logo-size);
  width: var(--logo-size);
}

.dialog-message {
  grid-area: message;
  margin: 10px 0 0;
}

.dialog-window {
  background: var(--color-bg-primary);
  border-radius: 8px;
  padding: var(--dialog-padding);
}

.dialog-workarea {
  display: flex;
  flex-direction: column;
  grid-area: workarea;
  margin: 10px 0 0;

  > * {
    margin-bottom: 5px;
  }
}

/// ABOUT DIALOG

.about-dialog {
  max-width: initial;

  .dialog-workarea > * {
    margin-bottom: 10px;
  }
}

.about-dialog-version-number {
  margin-left: 4px;
}

.about-dialog-version-checksum {
  font-size: small;
  font-style: italic;
  font-weight: normal;
  margin-left: auto;
  padding-left: 10px;
}

/// OPEN TORRENT DIALOG
.open-torrent {
  input {
    margin-bottom: 15px;

    &[type='file'] {
      width: 100%;
      box-sizing: border-box;
    }
  }

  #auto-start-label {
    margin-left: 5px;
  }
}

/// HOTKEYS DIALOG

.shortcuts-dialog {
  table {
    border-collapse: collapse;
    width: 100%;
  }

  th,
  td {
    border: 1px solid var(--color-border-stark);
    padding: 5px 10px;
  }
}

/// RENAME DIALOG

#torrent-rename-name {
  min-width: 400px;
}

/// SET-LOCATION DIALOG

#move-container #torrent-path {
  min-width: 400px;
}

/// STATISTICS DIALOG

.tabs-pages,
.inspector-info-page,
.statistics-dialog {
  .content {
    column-gap: 16px;
    display: grid;
    grid-row-gap: 6px;
    grid-template-columns: auto 1fr;
    margin-top: 4px;

    @include viewport-small {
      margin: 4px 0 16px;
    }
    @include viewport-medium {
      margin: 4px 16px 16px;
    }

    div {
      word-break: break-word;
    }
  }

  fieldset {
    border: 0;
    margin: 0;
    padding: 0;
  }

  legend {
    font-weight: bolder;
    margin-bottom: 4px;
  }

  span {
    overflow-wrap: anywhere;
  }
}

/// UPLOAD DIALOG

#free-space-text {
  display: inline-block;
  font-size: smaller;
  font-style: italic;
}

.upload-div {
  display: none;
}
